package com.york.eduservice.controller;


import com.york.eduservice.entity.subject.OneSubject;
import com.york.eduservice.service.EduSubjectService;
import com.york.utils.exception.result.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * @Description:课程科目 前端控制器
 * @Data: 2022/3/7 15:39
 * @Author: yangboxiong
 * @Version
 * @since JDK 1.8
 */
@Api(tags = "课程管理")
@RestController
@RequestMapping("/eduservice/subject")
public class EduSubjectController {
    @Autowired
    private EduSubjectService subjectService;

    /**
     * 添加课程分类
     * 获取上传过来的文件，把文件内容读取出来
     *
     * @param file
     * @return
     */
    @ApiOperation("Excel批量导入数据字典")
    @PostMapping("/addSubject")
    public R addSubject(@ApiParam(value = "Excel文件", required = true) MultipartFile file) {
        //上传过来的Excel文件
        subjectService.saveSubject(file, subjectService);
        return R.ok().message("批量导入成功");
    }

    /**
     * 课程分类列表功能（树形）
     *
     * @return
     */
    @ApiOperation("程分类的列表")
    @GetMapping("/getAllSubject")
    public R getAllSubject() {
        //list集合泛型是一级分类
        List<OneSubject> list = subjectService.getAllOneTwoSubject();
        return R.ok().data("list", list);
    }
}

